﻿using Fine.TestUtils;
using NUnit.Framework;



namespace Fine.Collections.Const
{
    [TestFixture]
    public class ConstTinySet_test
    {
        [Test]
        public void Test_SetOf1()
        {
            var set = CC1.TinySetOf(111L);

            set             ._is_not_null_();
            set.IsEmpty     ._false_();
            set.IsNotEmpty  ._true_();
            set.Count       ._equals_(1);
            set.FirstIndex  ._equals_(1);
            set.LastIndex   ._equals_(1);
            set.First       ._equals_(111L);
            set.Last        ._equals_(111L);
            set[1]          ._equals_(111L);
        }

        [Test]
        public void Test_SetOf2()
        {
            var set = CC1.TinySetOf(111L, 222L);

            set             ._is_not_null_();
            set.Count       ._equals_(2);
            set.FirstIndex  ._equals_(1);
            set.LastIndex   ._equals_(2);
            set.First       ._equals_(111L);
            set.Last        ._equals_(222L);
            set[1]          ._equals_(111L);
            set[2]          ._equals_(222L);
        }

        [Test]
        public void Test_SetOf0()
        {
            var set = CC1.TinySetOf<long>();

            set             ._is_not_null_();
            set.IsEmpty     ._true_();
            set.IsNotEmpty  ._false_();
            set.Count       ._equals_(0);
        }


        [TestCase(111L, 111L, 222L, 333L)]
        [TestCase(111L, 222L, 222L, 333L)]
        [TestCase(111L, 222L, 333L, 333L)]
        [TestCase(111L, 222L, 333L, 111L)]
        [TestCase(111L, 222L, 333L, 222L)]
        public void Test_RemoveDuplicates(long v1, long v2, long v3, long v4)
        {
            var set = CC1.TinySetOf(v1, v2, v3, v4);

            set.ToArray()  ._array_(111L, 222L, 333L);
        }


        [Test]
        public void Test_Plus_NewOne_2()
        {
            var source2 = CC1.TinySetOf(111L, 222L);
            var result2 = source2 + 999L;

            result2.ToArray()  ._array_(111L, 222L, 999L);
        }

        [Test]
        public void Test_Plus_NewOne_0()
        {
            var source0 = CC1.TinySetOf<long>();
            var result0 = source0 + 999L;

            result0.ToArray()._array_(999L);
        }


        [Test]
        public void Test_Plus_ExistentOne()
        {
            var source = CC1.TinySetOf(111L, 222L, 333L);
            var result = source + 222L;

            result._same_(source);
        }


        [Test]
        public void Test_Plus_SourceIsEmpty()
        {
            var source = CC1.TinySetOf<long>();
            var result = source + 222L;

            result         ._is_not_null_();
            result.Count   ._equals_(1);
            result         ._contains_(222L);
        }


        [Test]
        public void Test_Plus_SourceIsNull()
        {
            ConstTinySet<long> source = (ConstTinySet<long>) null;
            ConstTinySet<long> result = source + 333L;

            result         ._is_not_null_();
            result.Count   ._equals_(1);
            result         ._contains_(333L);
        }


        [TestCase(111L)]
        [TestCase(222L)]
        [TestCase(333L)]
        [TestCase(444L)]
        public void Test_Minus_Existent(long excludeItem)
        {
            var source = CC1.TinySetOf(111L, 222L, 333L, 444L);
            var result = source - excludeItem;

            result.Count           ._equals_(3);

            result.Contains(111L)  ._equals_(111L != excludeItem);
            result.Contains(222L)  ._equals_(222L != excludeItem);
            result.Contains(333L)  ._equals_(333L != excludeItem);
            result.Contains(444L)  ._equals_(444L != excludeItem);
        }


        [Test]
        public void Test_Minus_TheOnlyItem()
        {
            var source = CC1.TinySetOf(666666L);
            var result = source - 666666L;

            result   ._is_empty_();
        }


        [Test]
        public void Test_Minus_Unexistent()
        {
            var source = CC1.TinySetOf(111L, 222L, 888L, 999L);
            var result = source - 666L;

            result  ._same_(source);
        }


        [Test]
        public void Test_Minus_SourceIsEmpty()
        {
            var source = CC1.TinySetOf<long>();
            var result = source - 666L;

            result  ._is_not_null_();
            result  ._is_empty_();
        }


        [Test]
        public void Test_Minus_SourceIsNull()
        {
            ConstTinySet<long> source = (ConstTinySet<long>)null;
            ConstTinySet<long> result = source - 666L;

            result  ._is_null_();
        }


        [Test]
        public void Test_Minus_NullItem()
        {
            var source = CC1.TinySetOf<string>();
            var result = source - (string)null;

            result  ._is_not_null_();
            result  ._is_empty_();
        }

    }
}
